<template>
  <div class="container1" :class="{ print: type == '打印' }">
    <DocHeader fromDoc="missuctionRisk" :title="title"> </DocHeader>
    <div class="content">
      <div class="bort borl borr">
        <div class="pad8 ml-10 f-b">护理措施：</div>
        <el-checkbox
          v-model="checkAll"
          class="ml-30"
          :indeterminate="isIndeterminate"
          @change="handleCheckAllChange"
          >全选</el-checkbox
        >
        <el-checkbox-group
          v-model="pageData.s9"
          class="pb-10"
          @change="handleCheckedCitiesChange"
        >
          <el-checkbox
            v-for="(item, idx) in options"
            :key="idx"
            class="ml-30 mt-5"
            :label="item.value"
          >
            {{ item.label }}
          </el-checkbox>
        </el-checkbox-group>
      </div>
    </div>
    <div class="borb"></div>
  </div>
</template>

<script>
import { cloneDeep, pick } from 'lodash-unified'
import {
  computed,
  defineComponent,
  nextTick,
  onMounted,
  reactive,
  toRefs,
  watch
} from 'vue'

import DocHeader from '../DocHeader.vue'
import { baseData, options } from './baseData.js'

export default defineComponent({
  components: {
    DocHeader
  },
  props: {
    data: {
      type: Object,
      default: () => ({})
    },
    title: {
      type: String,
      default: ''
    },
    type: {
      type: String,
      default: ''
    }
  },
  setup(props) {
    const state = reactive({
      pageData: cloneDeep(baseData),
      isIndeterminate: false,
      checkAll: false,
      options: cloneDeep(options)
    })

    const sum = computed(() => {
      let sum = 0
      for (let i = 1; i <= 8; i++) {
        sum += Number(state.pageData[`s${i}`])
      }
      return sum
    })

    function initData() {
      if (props.data.jsonText && props.data.jsonText !== '{}') {
        const jsonText = JSON.parse(props.data.jsonText)
        state.pageData = Object.assign(cloneDeep(baseData), jsonText)
      } else {
        nextTick(() => {
          state.pageData = cloneDeep(baseData)
        })
      }
    }

    function handleCheckAllChange(val) {
      state.pageData.s9 = val ? state.options.map(res => res.value) : []
      state.isIndeterminate = false
    }
    function handleCheckedCitiesChange(value) {
      const checkedCount = value.length
      state.checkAll = checkedCount === state.options.length
      state.isIndeterminate =
        checkedCount > 0 && checkedCount < state.options.length
    }

    function getParams() {
      return state.pageData
    }

    watch(
      () => props.data,
      () => {
        initData()
      }
    )

    onMounted(() => {
      initData()
    })

    return {
      ...toRefs(state),
      sum,
      getParams,
      handleCheckAllChange,
      handleCheckedCitiesChange
    }
  }
})
</script>

<style lang="scss" scoped>
@import '@/views/doc/styles/doc-common.scss';
@import '@/views/doc/styles/doc-fix.scss';
$border: 1px solid #000;

::v-deep .el-radio {
  display: block;
  margin-right: 0;
  padding: 7px 5px;
}

::v-deep .el-checkbox {
  display: block;

  .el-checkbox__label {
    white-space: normal;
    vertical-align: top;
    line-height: 18px;
  }
}

.f-b {
  font-weight: bold;
}

.pad8 {
  padding: 8px 0;
}

.mt-6 {
  margin-top: 6px;
}

.p-12-5 {
  padding: 12px 5px;
}

.container1 {
  padding: 20px 0;
  // margin: getpx(30) auto 0;
  // width: calc(100% - 66px);
  font-family: SiYuanSong-Medium;
  text-align: start;

  span {
    font-size: 14px;
  }

  .print-span {
    display: inline-block;
    font-size: 12px;
    border-bottom: 1px solid;
    vertical-align: text-bottom;
    word-break: break-all;
  }
}

.bor-t-box {
  margin-bottom: 10px;
  width: 100%;
  border-top: 1px solid #000;
}

.mt {
  &-3 {
    margin-top: 3px;
  }

  &-5 {
    margin-top: 5px;
  }
}

.ml {
  &-30 {
    margin-left: 30px;
  }

  &-38 {
    margin-left: 38px;
  }

  &-42 {
    margin-left: 42px;
  }

  &-50 {
    margin-left: 50px;
  }

  &-60 {
    margin-left: 60px;
  }

  &-70 {
    margin-left: 70px;
  }

  &-73 {
    margin-left: 73px;
  }

  &-84 {
    margin-left: 84px;
  }

  &-240 {
    margin-left: 240px;
  }
}

.mb {
  &-3 {
    margin-bottom: 3px;
  }

  &-10 {
    margin-bottom: 10px;
  }
}

.mr {
  &-10 {
    margin-right: 10px;
  }

  &-15 {
    margin-right: 15px;
  }

  &-20 {
    margin-right: 20px;
  }
}

.m-0 {
  margin: 0;
}

.m-0-2 {
  margin: 0 2px;
}

.p-2 {
  padding: 2px;
}

.p-10-0 {
  padding: 10px 0;
}

.pb-10 {
  padding-bottom: 10px;
}

.txt-c {
  text-align: center;

  input {
    text-align: center;
  }
}

.w-1 {
  width: 75px;
}

.w-2 {
  width: 260px;
}

.w-3 {
  width: 89px;
}

.w-4 {
  width: 40% !important;
}

.w-5 {
  width: 76px !important;

  :deep {
    .el-input {
      width: 76px;
    }
  }
}

.w-6 {
  width: 66px;
}

.w-7 {
  width: 100px;
}

.w-8 {
  width: 14px;
}

.w-9 {
  width: 74px;

  :deep {
    .el-input {
      width: 74px;
    }
  }
}

.w-10 {
  width: 25px;
}

.w-11 {
  width: 116px;
}

.w-12 {
  width: 60px;
}

.w-13 {
  width: 127px;
}

.relative {
  position: relative;
}

input {
  margin: 4px 2px;
  font-size: 12px;
}

.flex-end {
  justify-content: flex-end;
}

.inline-block {
  display: inline-block;
}

::v-deep {
  .textarea {
    flex: 1;
    margin-left: 5px;

    .el-textarea__inner {
      padding: 0;
      font-size: 14px;
      color: #000;
      border: none;
      line-height: 1.15;
      resize: none;
      word-break: break-all;
    }
  }

  .el-cascader__tags {
    width: 100%;
    transform: translateY(-61%);

    .el-tag {
      max-width: 60%;
    }
  }

  .el-date-editor {
    padding: 2px;
    width: 100px;

    .el-input__inner {
      font-size: 14px;
    }

    .el-input__suffix {
      display: inline-block;
    }
  }

  .el-select,
  .el-autocomplete {
    margin: 4px 2px;
    border-bottom: 1px solid;

    .el-input__suffix {
      display: inline-block;
      right: -6px;
      top: -3px;

      .el-icon-arrow-up {
        display: none;
      }

      .el-icon-circle-close {
        color: red;
      }
    }

    .el-input__inner {
      text-align: center;
      height: 15px;
      line-height: 15px;
    }
  }

  .el-cascader {
    border-bottom: 1px solid;
    line-height: 15px;
  }

  .el-cascader__search-input {
    height: 15px;
  }

  .el-input .el-input__inner {
    height: 15px !important;
    font-size: 12px;
  }

  .el-input.is-disabled .el-input__inner {
    background-color: #fff;
  }

  input:disabled {
    color: #000;
    background: #fff;
  }

  .el-cascader__search-input {
    margin-left: 0;
  }
}

.img {
  width: 20px;
  vertical-align: sub;
  cursor: pointer;

  &.add {
    margin: 5px 10px 0 0;
  }

  &:not(.add) {
    position: absolute;
    right: -20px;
    top: 3px;
  }
}

.print {
  height: 1188px;

  ::v-deep {
    .el-select {
      padding-bottom: 1px;
      transform: translateY(-1px);
    }
  }

  .container1 {
    .print-spans {
      padding-bottom: 1px;
      transform: translateY(1px);
    }
  }

  input {
    padding-bottom: 1px;
    line-height: 14px;
  }
}
$border: 1px solid #000;

.container {
  padding-top: getpx(50);
  // margin: getpx(30) auto 0;
  // width: calc(100% - 40px);
  font-family: SiYuanSong-Medium;
  text-align: start;
}

.content {
  margin-top: 5px;
}

.inputStyle {
  // font-size: 10px;
  border: none;
  background-color: rgba($color: #000, $alpha: 0%);
  outline: none;
  width: 90%;
  height: 100%;
}

.w40 {
  width: 40px;
}

.w60 {
  width: 60px;
}

.flex {
  display: flex;
}

.tac {
  display: flex;
  justify-content: center;
  align-items: center;
  flex-direction: column;
}

.sta {
  display: flex;
  flex-direction: column;
  justify-content: flex-start;
}

.flex {
  @for $i from 1 through 30 {
    &-#{$i} {
      flex: $i;
    }
  }
}

.mb8 {
  margin-bottom: 8px;
}

.borr {
  border-right: 1px solid #000;
}

.bort {
  border-top: 1px solid #000;
}

.borl {
  border-left: 1px solid #000;
}

.borb {
  border-bottom: 1px solid #000;
}

.pad10 {
  padding: 10px;
}

.pad5 {
  padding: 5px;
}

.h30 {
  height: 38px;
}
</style>
